
//
//  NavagationViewController.swift
//  新浪微博
//
//  Created by yaozhen on 2017/11/27.
//  Copyright © 2017年 ZYZ. All rights reserved.
//

import UIKit

class NavagationViewController: UINavigationController {
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的navigationBar
        navigationBar.isHidden = true
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //如果不是栈底控制器才需要隐藏，根控制器不需要处理
        if childViewControllers.count>0 {
            //隐藏底部tabbar
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as?BaseViewController {
                var title = "返回"
                
                
                if childViewControllers.count == 1{
                    title = childViewControllers.first?.title ?? "返回"
                }
                //左侧按钮为返回按钮
                vc.navIem.leftBarButtonItem = UIBarButtonItem.init(title: title, target: self, action: #selector(popToparent), isBack:true)
            }
        }
        //判断控制器类型
        
        super.pushViewController(viewController, animated: true)
    }
    @objc private func popToparent(){
        popViewController(animated: true)
    }

}
